package com.hkts.management.unattended.poundroom.service.serviceimpl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hkts.management.unattended.poundroom.entity.YbMutualSovouch;
import com.hkts.management.unattended.poundroom.entity.YbMutualWarehouse;
import com.hkts.management.unattended.poundroom.mapper.YbMutualWarehouseMapper;
import com.hkts.management.unattended.poundroom.service.IYbMutualWarehouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author zy
 * @since 2021-10-13
 */
@Service
@Transactional
@DS("slave")
public class YbMutualWarehouseSlaveServiceImpl extends ServiceImpl<YbMutualWarehouseMapper, YbMutualWarehouse>  {


    @Autowired
    private YbMutualWarehouseMapper ybMutualWarehouseMapper;

    public IPage<YbMutualWarehouse> selectPage(Page<YbMutualWarehouse> page, YbMutualWarehouse ybMutualWarehouse) {
        QueryWrapper<YbMutualWarehouse> query = Wrappers.query();
        return ybMutualWarehouseMapper.selectPage(page, query);
    }


    public List<YbMutualWarehouse> selectList(YbMutualWarehouse ybMutualWarehouse) {
        QueryWrapper<YbMutualWarehouse> query = Wrappers.query();
        return ybMutualWarehouseMapper.selectList(query);
    }
    public List<YbMutualWarehouse> getUpdateTimeData(LocalDateTime updateTime,int flag){
        QueryWrapper<YbMutualWarehouse> query = Wrappers.query();
        query.select("top 1000 cWhCode, cWhName, bDel, doptTime, dcreateTime, dmodifyTime, ddeleteTime, u8optStatus, bmutualStatus ");
        query.lambda().gt(updateTime!=null,YbMutualWarehouse::getDoptTime,updateTime);
        query.orderByAsc("cWhCode");
        if(flag!=0){
            Integer count=flag*1000;
            String maxId=ybMutualWarehouseMapper.getAutoIdMax(count);
            query.ge("cWhCode",maxId);
        }
        return ybMutualWarehouseMapper.selectList(query);
    }
    public Integer getUpdateTimeCount(LocalDateTime updateTime){
        QueryWrapper<YbMutualWarehouse> query = Wrappers.query();
        query.lambda().gt(updateTime!=null,YbMutualWarehouse::getDoptTime,updateTime);
        Integer count=ybMutualWarehouseMapper.selectCount(query);
        double flag=count;
        double total=flag/1000;
        return (int)Math.ceil(total);
    }
    public Integer getBmutualStatusCount(){
        QueryWrapper<YbMutualWarehouse> query = Wrappers.query();
        query.lambda().eq(YbMutualWarehouse::getBmutualStatus,0);
        Integer count=ybMutualWarehouseMapper.selectCount(query);
        double flag=count;
        double total=flag/1000;
        return (int)Math.ceil(total);
    }
    public List<YbMutualWarehouse> getBmutualStatuData(int flag){
        QueryWrapper<YbMutualWarehouse> query = Wrappers.query();
        query.select("top 1000 cWhCode, cWhName, bDel, doptTime, dcreateTime, dmodifyTime, ddeleteTime, u8optStatus, bmutualStatus ");
        query.lambda().eq(YbMutualWarehouse::getBmutualStatus,0);
        query.orderByAsc("cWhCode");
        if(flag!=0){
            Integer count=flag*1000;
            String maxId=ybMutualWarehouseMapper.getAutoIdMax(count);
            query.ge("cWhCode",maxId);
        }
        return ybMutualWarehouseMapper.selectList(query);
    }

}
